//
//  HNSH_ShopDetailTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/2.
//

#import "HNSH_ShopDetailTopView.h"

@interface HNSH_ShopDetailTopView ()
/** 搜索框灰色背景 */
@property (nonatomic, strong)UIView * grayBgView;
/** 搜索图片 */
@property (nonatomic, strong)UIImageView * searchImgView;
/**  */
@property (nonatomic, strong)UILabel * label;
@end

@implementation HNSH_ShopDetailTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addSubview:self.grayBgView];
    [self.grayBgView addSubview:self.searchImgView];
    [self.grayBgView addSubview:self.label];
    
    [self.grayBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(32);
    }];
    
    [self.searchImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.equalTo(self.grayBgView.mas_centerY);
        make.width.height.mas_equalTo(16);
    }];
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(41);
        make.centerY.equalTo(self.grayBgView.mas_centerY);
        make.height.mas_equalTo(20);
    }];
    
}

//MARK: 搜索
- (void)gesAction{
    if (self.searchBlock) {
        self.searchBlock();
    }
}

#pragma mark lazy
- (UIView *)grayBgView{
    if (!_grayBgView) {
        _grayBgView = [UIView new];
        _grayBgView.backgroundColor = [UIColor colorWithHexString:@"#E3E6EB"];
        _grayBgView.layer.cornerRadius = 10;
        _grayBgView.layer.masksToBounds = YES;
        
        UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesAction)];
        [_grayBgView addGestureRecognizer:ges];
    }
    return _grayBgView;
}

- (UIImageView *)searchImgView{
    if (!_searchImgView) {
        _searchImgView = [UIImageView new];
        _searchImgView.image = [UIImage imageNamed:@"home_nav_search_icon"];
    }
    return _searchImgView;
}

- (UILabel *)label{
    if (!_label) {
        _label = [UILabel new];
        _label.textColor = [UIColor appGrayLabelColor];
        _label.font = [UIFont systemFontOfSize:14];
        _label.text = @"搜索商品";
    }
    return _label;
}

@end
